from Final_assignment.Stock import Stock
from Final_assignment.tools import *

kline_nums = 10  # k线图中的k线个数
cycles_forecast = 5  # 预测的天数


def genenate_Kline_diagram(cycle, stock_list, mode):
    form_list1 = read_file_list("files/", "form_list1.txt")  # 读取k线形态1
    form_list2 = read_file_list("files/", "form_list2.txt")  # 读取k线形态2
    if mode == "test":  # 测试模式
        form_list1 = ["2CROWS"]
    for stock in stock_list:
        stock = stock_code_standardization(stock)  # 股票代码标准化
        one_stock = Stock(stock, cycle)  # 创建股票对象
        if cycle == "daily":
            one_stock.get_price_daily()
        elif cycle == "weekly":
            one_stock.get_price_weekly()
        one_stock.find_stock_form(form_list1, form_list2)  # 识别形态
        one_stock.draw_and_marker(form_list1 + form_list2, kline_nums, cycles_forecast)  # 绘制形态k线图和进行标记
        print("{} froms are be found in {}".format(one_stock.picture_nums, stock))
        # print(one_stock.stock_data)
        print(stock, " is genenate successfully")
